package com.GUI.lesson02;

/*
//简易计算机
public class TestCalc {
    public static void main(String[] args) {
        new Claculator();
    }
}
class Claculator extends Frame{
    public Claculator(){
        //三个文本框
        TextField num1 = new TextField(10);
        TextField num2 = new TextField(10);
        TextField num3 = new TextField(20);
        //1个按钮
        Button button = new Button("=");

        button.addActionListener(new MyClaculatorListener(num1,num2,num3));
        //一个标签‘+ ’
        Label label = new Label("+");

        //布局
        setLayout(new FlowLayout());
        add(num1);
        add(label);
        add(num2);
        add(button);
        add(num3);

        pack();
        setVisible(true);
    }
}
//监听器类
class MyClaculatorListener implements ActionListener{

    private TextField num1,num2,num3;
    public MyClaculatorListener(TextField num1,TextField num2,TextField num3){
        this.num1 = num1;
        this.num2 = num2;
        this.num3 = num3;
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        //获得加数和被加数
        int i =Integer.parseInt(num1.getText());
        int j =Integer.parseInt(num2.getText());
        //= 进行加法运算，放到第三个框
        num3.setText("" + (i+j));//括号是防止i和j被当作字符去运算
        //清除前两个框
        num1.setText(null);
        num2.setText(null);
    }
}

 */